const { Menu, app, dialog, shell } = require("electron");

const dialogMenu = (win) => {
  const config = [
    {
      label: app.name,
      submenu: [
        {
          label: "访问官网",
          click: async () => {
            win.focus();
            const res = await dialog.showMessageBox(win, {
              title: "后盾人",
              detail: "晚八点直播",
              buttons: ["取消", "确定"],
              cancelId: 0,
              checkboxLabel: "确定访问吗？", // 复选框
              // checkboxChecked: true,// 复选框默认选中
            });
            if (!res.checkboxChecked) {
              return dialog.showErrorBox("温馨提示", "你没有确认复选框");
            }
            if (res.response == 1) {
              shell.openExternal("https://www.houdunren.com");
            }
          },
        },
        {
          label: "退出",
          click: async () => {
            const res = await dialog.showMessageBox(win, {
              title: "后盾人",
              detail: "你确定要退出吗？",
              buttons: ["取消", "确定"],
              cancelId: 0,
              /**明确取消操作对应的按钮：cancelId 能让开发者明确指定在用户取消对话框操作时，返回的按钮索引是哪一个。当用户关闭对话框或者按下 Esc 键，对话框会将 cancelId 所指定的按钮索引作为响应结果返回。 */
              // 硬解释，点击了按钮里面的第二个
            });

            if (res.response == 1) app.quit();
          },
        },
      ],
    },
  ];

  Menu.setApplicationMenu(Menu.buildFromTemplate(config));
};

module.exports = { dialogMenu };
